﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SCCN.BLL;
using SCCN.DAL;
using SCCN.Utility;
using System.Text;

/// <summary>
///CreateHeader 的摘要说明
/// </summary>
public class CreateHeader : CreatePage
{
    CategoryBLL bllCategory = CategoryBLL.getInstance();
    public CreateHeader()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    /// <summary>
    /// 生成
    /// </summary>
    /// <returns></returns>
    public static bool Create()
    {
        string path = ReaderTemplate("~/template/header.html");
        string content = Fun_Rapalce_Tag(path);
        try
        {
            CreateHTMLHelper.CreateFile(HttpContext.Current.Server.MapPath("~/header.htm"), CreatePage.encode, content);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return true;
    }

    /// <summary>
    /// 替换页面标签
    /// </summary>
    /// <param name="content"></param>
    /// <returns></returns>
    public static string Fun_Rapalce_Tag(string content)
    {
        //标签存放字典
        Dictionary<string, string> dict = new Dictionary<string, string>();
        dict.Add("{$Header_Category$}", Header_Category());//头部分类
        content = CreateHTMLHelper.ReplaceTag(dict, content);
        return content;
    }

    /// <summary>
    /// 读取头部显示的分类
    /// </summary>
    /// <returns></returns>
    public static string Header_Category()
    {
        StringBuilder str = new StringBuilder();
        int rowCount = 0;
        SC_Category obj = new SC_Category();
        obj.CategoryName = "";
        obj.IsDelete = false;
        CategoryBLL bllCategory = CategoryBLL.getInstance();
        int i = 0;
        List<SC_Category> listCategory = bllCategory.GetCategoryByCondition(obj, 1, 5, out rowCount);
        foreach (SC_Category var in listCategory)
        {
            if (var.CategoryName == "淘宝商城")
            {
                continue;
            }
            if (i == 0)
            {
                str.AppendLine("<li class=\"no-bg\">");
                str.AppendLine("<strong>");
                str.AppendLine("<a href=\"/list.aspx?categoryid=" + var.Id.ToString() + "\">" + var.CategoryName + "</a>");
                str.AppendLine("</strong>");
                str.AppendLine("</li>");
            }
            else
            {
                str.AppendLine("<li><a href=\"/list.aspx?categoryid=" + var.Id.ToString() + "\">" + var.CategoryName + "</a></li>");
            }
            i++;
        }
        str.AppendLine("<li><a href=\"/hd1.html>八周年专题</a></li>");
        return str.ToString();
    }
}